cssjshtml vue.js 多个vue实例

葫芦的运维日志

下一篇 搜索 上一篇

浏览量 4434

2018/12/03 02:38


 

 

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>if</title>
</head>
<body>
<div id="vue-app">
    <h1> 实例化多个对象</h1>
    <div id="vue-app-one">
    <p>    {{ title }}</p>
       <p> {{ greet }}</p>

    </div>
    <div id="vue-app-two">
<p> {{ title }}</p>
     <p>   {{ greet }}</p>
        <button v-on:click="change">change one</button>
    </div>

    <script src="/static/js/vue.min.js"></script>
    <script>
        var one = new Vue({
            el: "#vue-app-one",
            data: {
                title: "app-one"
            },
            methods: {},
            computed: {
                greet:function () {
                    return "computed app one"
                }
            }
        });

        var two = new Vue({
            el: "#vue-app-two",
            data: {
                title: "app-two"
            },
            methods: {
                change:function () {
                    one.title="changed app one"
                }
            },
            computed: {
                                greet:function () {
                    return "computed app two"
                }
            }
        });
        two.title="changed app two";
    </script>
</body>
</html>

 

葫芦的运维日志

打赏

上一篇 搜索 下一篇
© 冰糖葫芦甜(bthlt.com) 2021 王梓打赏联系方式 陕ICP备17005322号-1